#include "Course.h"
#include <QDataStream>

Course::Course()
{

}

Course::Course(QString name, QString code, int numOfSections)
{
    this->code = code;
    this->name = name;
    this->numberOfSections = numOfSections;
}

Course::Course(QString name, QString code, int maxSections, QVector<Course> prereqList, QVector<Course> antireqList, QVector<ClassSection> classSectionList, QVector<Exam> examList, QVector<Assignment> assignmentList, DateRange duration, CourseOutline outline)
{
    this->code = code;
    this->name = name;
    this->maxSections = maxSections;
    this->prereqList = prereqList;
    this->antireqList = antireqList;
    this->classSectionList = classSectionList;
    this->examList;
    this->assignmentList = assignmentList;
    this->duration = duration;
    this->outline = outline;
}

QString Course::getName() const
{
    return this->name;
}

QString Course::getName()
{
    return this->name;
}

QString Course::getCode() const
{
    return this->code;
}

QString Course::getCode()
{
    return this->code;
}

int Course::getMaxSections() const
{
    return this->maxSections;
}
QVector<Course> Course::getPrereqList() const
{
    return this->prereqList;
}
QVector<Course> Course::getAntireqList() const
{
    return this->antireqList;
}
QVector<ClassSection> Course::getClassSection() const
{
    return this->classSectionList;
}
QVector<Exam> Course::getExamList() const
{
    return this->examList;
}
QVector<Assignment> Course::getAssignmentList() const
{
    return this->assignmentList;
}
DateRange Course::getDuration() const
{
    return this->duration;
}

CourseOutline Course::getOutline() const
{
    return this->outline;
}

int Course::getNumberOfSections() const
{
    return this->numberOfSections;
}

void Course::setNumberOfSections(int newNum)
{
    this->numberOfSections=newNum;
}

void Course::setName(QString newName)
{
    this->name = newName;
}

void Course::setCode(QString newCode)
{
    this->code = newCode;
}

void Course::setDuration(DateRange duration)
{
    this->duration = duration;
}

void Course::setOutline(CourseOutline outline)
{
    qDebug() << 4;
    this->outline = outline;
}

void Course::setOutline(CourseOutline *outline)
{
    this->outline = *outline;
}

void Course::addPrereq(Course course)
{
    prereqList.append(course);
}

void Course::addAntireq(Course course)
{
    antireqList.append(course);
}

void Course::addClassSection(ClassSection section)
{
    classSectionList.append(section);
}

void Course::addClassSectionAt(ClassSection section, int index)
{
    classSectionList.insert(index, section);
}

void Course::addExam(Exam exam)
{

}

void Course::addAssignment(Assignment assignment)
{

}

Course Course::removePrereq(QString courseCode)
{
    int size=prereqList.size();
    int i=0;
    //    Course byeCourse=NULL;
    while(i<size)
    {
        if(prereqList[i].getCode().compare(courseCode)==0)
        {
            Course  byeCourse=prereqList[i];
            prereqList.remove(i);
            return byeCourse;
        }
        i++;
    }
    return *(new Course());
}


QVector<Course> Course::getPrereq()
{
    return prereqList;
}

QVector<ClassSection> *Course::getClaSect()
{
    return &(this->classSectionList);
}

QVector<Course> Course::getAntireq()
{
    return antireqList;
}

ClassSection Course::removeClassSection(int sectionNumber)
{
    ClassSection retClassSect=classSectionList[sectionNumber];
    classSectionList.remove(sectionNumber);
    return retClassSect;
}

Course Course::removeAntireq(QString courseCode)
{
    int size=antireqList.size();
    int i=0;
    //    Course byeCourse=NULL;
    while(i<size)
    {
        if(antireqList[i].getCode().compare(courseCode)==0)
        {
            Course  byeCourse=antireqList[i];
            antireqList.remove(i);
            return byeCourse;
        }
        i++;
    }
    //    return byeCourse;
    return *(new Course());
}

/*
Course Course::removePrereq(string courseCode)
{
    return NULL; // !!!!!!!!!!!!!! FOR NOW!!!!!!!!!!!!!!!!!!!!!
}

Course Course::removeAntireq(string courseCode)
{
    return NULL; // !!!!!!!!!!!!!! FOR NOW!!!!!!!!!!!!!!!!!!!!!
}

ClassSection Course::removeClassSection(int sectionNumber)
{
    return NULL; // !!!!!!!!!!!!!! FOR NOW!!!!!!!!!!!!!!!!!!!!!
}

Exam Course::removeExam(int examNumber)
{
    return NULL; // !!!!!!!!!!!!!! FOR NOW!!!!!!!!!!!!!!!!!!!!!
}

Assignment Course::removeAssignment(int assignmentNumber)
{
    return NULL; // !!!!!!!!!!!!!! FOR NOW!!!!!!!!!!!!!!!!!!!!!
}
*/

QDataStream &operator<<(QDataStream &out, const Course &data)
{
    out << data.getName() << data.getCode() << data.getMaxSections() <<data.getNumberOfSections() << data.getPrereqList()
        << data.getAntireqList()
        << data.getClassSection() << data.getExamList() << data.getAssignmentList() << data.getDuration() << data.getOutline();
    return out;
}

QDataStream &operator>>(QDataStream &in, Course &data)
{
    QString name;
    QString code;
    int maxSections;
    int numberOfSections;
    QVector<Course> prereqList;
    QVector<Course> antireqList;
    QVector<ClassSection> classSectionList;
    QVector<Exam> examList;
    QVector<Assignment> assignmentList;
    DateRange duration;
    CourseOutline outline;

    in >> name >> code >> maxSections >> numberOfSections >> prereqList >> antireqList >> classSectionList >> examList >> assignmentList >> duration >> outline;
    data = Course(name, code,maxSections, prereqList, antireqList, classSectionList, examList, assignmentList, duration, outline);
    return in;
}
